#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    //1、设置行数，列数
    ui->tableWidget->setRowCount(5);
    ui->tableWidget->setColumnCount(3);
    //2、设置标题
    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"英雄"<<"型别"<<"年龄");
    //3、添加数据
    QStringList heroNames = QStringList()<<"亚瑟"<<"妲己"<<"赵云"<<"随悟空"<<"安其拉";
    QStringList heroGender = QStringList()<<"男"<<"女"<<"男"<<"其他"<<"女";
    QStringList heroAge = QStringList()<<"12"<<"34"<<"22"<<"34"<<"12";
    for(int row = 0; row < 5; ++row){
        ui->tableWidget->setItem(row,0,new QTableWidgetItem(heroNames[row]));
        ui->tableWidget->setItem(row,1,new QTableWidgetItem(heroGender[row]));
        ui->tableWidget->setItem(row,2,new QTableWidgetItem(heroAge[row]));
    }

}

Widget::~Widget()
{
    delete ui;
}
